//    package com.smart_campus.activiti.controller;
//
//
//import com.o2o.Service.ActivitiService;
//import com.o2o.vo.ActivitiVo;
//import lombok.extern.slf4j.Slf4j;
//import org.activiti.engine.*;
//import org.activiti.engine.identity.User;
//import org.activiti.engine.repository.Deployment;
//import org.activiti.engine.repository.ProcessDefinition;
//import org.activiti.engine.repository.ProcessDefinitionQuery;
//import org.activiti.engine.runtime.ProcessInstance;
//import org.activiti.engine.task.Task;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpSession;
//import java.util.*;
//
//@Controller
//@Slf4j
//@RequestMapping("/user")
//public class ActivitiController {
//    @Autowired
//    private ProcessEngine processEngine;
//    @Autowired
//    private TaskService taskService;
//    @Autowired
//    private RuntimeService runtimeService;
//    @Autowired
//    private HistoryService historyService;
//    @Autowired
//    private RepositoryService repositoryService;
//
//    @Autowired
//    private IdentityService identityService;
//
//    @Resource
//    private ActivitiService is;
//
//
//
//    @RequestMapping("/zz")
//    public String zz(){
//        return "apply";
//    }
//
//    @RequestMapping("/index")
//    public String zzz(){
//        return "index";
//    }
//
//    @RequestMapping("/login")
//    public String login(HttpSession session, String actorId) {
//        System.out.println("当前登录用户：" + actorId);
//        session.setAttribute("actorId", actorId);
//        System.out.println(actorId.toString());
//
//        return "menu";
//    }
//
//    //部署流程资源【第一种方式：classpath】
//    @RequestMapping("/deploy1")
//    public String deploy1( ){
//        Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service
//                .createDeployment()//创建部署对象
//                .name("请假申请审核流程")//声明流程的名称
//                .addClasspathResource("processes/zzz.bpmn")//加载资源文件，一次只能加载一个文件
//                .addClasspathResource("processes/zzz.png")//
//                .deploy();//完成部署
//        System.out.println("部署ID："+deployment.getId());//
//        System.out.println("部署时间："+deployment.getDeploymentTime());
//        return "deploy";
//    }
//
//
//
//
//    //查看所有流程定义
//    @RequestMapping("/processDefinition")
//    public String processDefinition(Model model) {
//        ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
//        query.orderByProcessDefinitionVersion().desc();//根据流程版本倒叙（最新的排在前面）
//        //query.latestVersion();//获取最新的一个版本
//        List<ProcessDefinition> list = query.list();
//        model.addAttribute("list", list);
//        return "listProcessDefinition";
//    }
//
//    @RequestMapping("/delProcessDefinition")
//    public String delProcessDefinition(String did) {
//        repositoryService.deleteDeployment(did, true);
//        System.out.println("zzzzzzz"+did);
//        return "redirect:processDefinition";
//    }
//
//    //请假申请
//    @RequestMapping("/apply")
//    public String apply(ActivitiVo jobs,HttpSession session){
//
//        jobs.setJobDate(new Date());//单据创建时间
//        jobs.setProcessFlag(1);//单据状态 1、审批中 2、审批通过
//        jobs.setUserId(session.getAttribute("actorId").toString());
//        //保存单据
//        is.addjob(jobs);
//
//
//        //设置流程变量（单据和流程实例绑定的中间变量）
//        Map vars = new HashMap();
//        vars.put("userId",jobs.getUserId());//用户名称
//        vars.put("day",jobs.getDay());//天数
//        vars.put("jobId",jobs.getJobId());//单据
//
//        String jb = jobs.getJobType();
//        System.out.println("流程key"+jb);
//
//        // 流程定义的Key
//        String processDefinitionKey = jb;
//        Map<String, Object> variables = new HashMap<String, Object>();
//        variables.put("userId", "user1");//这里传入id为user1的用户
//        variables.put("Day",jobs.getDay());
//        ProcessInstance processInstance = processEngine.getRuntimeService()// 与正在执行的流程实例和执行对象相关的Service
//                .startProcessInstanceByKey(processDefinitionKey,variables);// 使用流程定义的key启动流程实例，key对应leave.bpmn文件中id的属性
//        System.out.println("流程实例ID:" + processInstance.getId());// 流程实例ID:
//        System.out.println("流程定义ID:" + processInstance.getProcessDefinitionId());// 流
//
//
//
////        通过流程实例ID获取到当前正在实行的任务(填写申请也是一个任务)
//        Task task =  taskService.createTaskQuery().processInstanceId(processInstance.getId()).orderByProcessInstanceId().desc().singleResult();
////        完成这个任务
//        taskService.complete(task.getId(),vars);
//        return "redirect:myjob";
//
//    }
//
//
//    @RequestMapping("/myjob")
//    public String myjob(HttpSession session,Model model){
//        String actorId  = session.getAttribute("actorId").toString();
//        List list = is.selmyjob(actorId);
//        System.out.println("selmyjob"+list);
//        model.addAttribute("jobList",list);
//        return "myjob";
//    }
//
//    //查看我的任务
//    @RequestMapping("/myTask")
//    public String myTask(HttpSession session,Model model){
//        String actorId = session.getAttribute("actorId").toString();
//        User user = identityService.createUserQuery()
//                .userFirstName(actorId)
//                .singleResult();
//        String zz = user.getId();
//        //根据用户名称查找办理人是我的任务(act_ru_task)
//        List<Task> list = taskService.createTaskQuery().taskAssignee(zz).list();
//        model.addAttribute("taskList",list);
//        return "myTask";
//    }
//
//      //任务详情
////    @RequestMapping("/taskDetail")
////    public String taskDetail(String taskId,String instId,Model model){
////        //获取单据详情(根据任务ID获取单据ID)
////        int jobid = Integer
////                .parseInt(taskService.getVariable(taskId,"jobId")
////                        .toString());
////        ActivitiVo job =  is.seljobbyid(jobid);
////
////        //通过流程实例ID查询流程实例对象
////        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
////                .processInstanceId(instId)
////                .singleResult();
////        //根据任务ID查询任务实例对象
////        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
////        System.out.println("实例对象"+task);
////        //根据流程实例ID查询历史备注集合
////        List<Comment> commentList = taskService.getProcessInstanceComments(instId);
////        System.out.println("历史合集"+commentList);
//
////        //获取流程定义id
////        String processDefineId = task.getProcessDefinitionId();
////        //查询流程定义实体对象
////        ProcessDefinitionEntity pdentity = (ProcessDefinitionEntity)processEngine
////                .getRepositoryService().getProcessDefinition(processDefineId);
////        //获取当前活动id
////        String activeId = processInstance.getActivityId();
////        System.out.println("当前活动ID "+activeId);
////
////
////        BpmnModel modelz = repositoryService.getBpmnModel(activeId);
////        if(model != null) {
////            Collection<FlowElement> flowElements = modelz.getMainProcess().getFlowElements();
////            for(FlowElement e : flowElements) {
////                System.out.println("flowelement id:" + e.getId() + "  name:" + e.getName() + "   class:" + e.getClass().toString());
////            }
////        }
////
////        model.addAttribute("commentList",commentList);//历史审批信息
//////        model.addAttribute("plist",plist);
////        model.addAttribute("taskId",taskId);
////        model.addAttribute("job",job);
//
////        return "adult";
////    }
//
//    //查看当前任务进度
//    @RequestMapping("/progress")
//    public String progress(HttpSession session,Model model){
//        String actorId = session.getAttribute("actorId").toString();
//        User user = identityService.createUserQuery()
//                .userFirstName(actorId)
//                .singleResult();
//        String zz = user.getId();
//        String zzz = user.getFirstName();
//        //根据用户名称查找办理人
//        List<Task> list = taskService.createTaskQuery().taskAssignee(zz).list();
//
//
//        model.addAttribute("taskList",list);
//
//        return "proress";
//    }
//}
